package com.heartware.sh.blackhole.ui.fragment.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.heartware.sh.blackhole.R;

/**
 * Created by Administrator on 2016/11/25 0025.
 */
public abstract class BaseFragment extends Fragment {

    protected Context mContext;

    private View view;

    private LinearLayout ll_content;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        mContext = getContext();

        view = inflater.inflate(R.layout.fragment_base, container, false);

        ll_content = (LinearLayout) view.findViewById(R.id.ll_content);

        setContentView(getLayoutId());

        initView();

        setListener();

        return view;
    }

    /**
     * 初始化控件..
     */
    public void initView(){}


    /**
     * 设置监听器.
     */
    public void setListener(){}

    /**
     * 获取资源ID
     * @return
     */
    public abstract int getLayoutId();


    public void setContentView(@LayoutRes int layoutResID) {
//        super.setContentView(layoutResID);
        setContentView(View.inflate(mContext, layoutResID, null));
    }

    public void setContentView(View view) {
//        super.setContentView(view);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        ll_content.addView(view, params);
    }

    public View findViewById(@IdRes int id) {
        return ll_content.findViewById(id);
    }



}
